Add default values handling to xcsv character fields.
authoralexmot <alexmot@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Thu, 30 Sep 2004 12:37:36 +0000 (12:37 +0000)
committeralexmot <alexmot@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Thu, 30 Sep 2004 12:37:36 +0000 (12:37 +0000)
gpsbabel/csv_util.c
gpsbabel/style/README.style

index 6330ff33f3fb8e847ecb6e4ee8708c75b9da6677..4d426382ca34638d59cda162c167186075ab872e 100644 (file)
@@ -136,7 +136,7 @@ csv_stringtrim(const char *string, const char *enclosure, int strip_max)
     if (elen) {
        while (
               (stripped < strip_max) &&
-              ((size_t) (p2 - p1) > elen) &&
+              ((size_t) (p2 - p1) >= elen) &&
               (strncmp(p1, enclosure, elen) == 0) &&
               (strncmp((p2 - elen + 1), enclosure, elen) == 0)) {
            p2 -= elen;
@@ -836,8 +836,7 @@ xcsv_waypt_pr(const waypoint *wpt)
             else
                 shortname = csv_stringclean(wpt->description, xcsv_file.badchars);
         } else {
-            /* no description available */
-            shortname = xstrdup("");
+            /* no shortname available -- let shortname default on output */
         }
     } else{
         shortname = csv_stringclean(wpt->shortname, xcsv_file.badchars);
@@ -847,7 +846,7 @@ xcsv_waypt_pr(const waypoint *wpt)
         if (shortname) {
             description = csv_stringclean(shortname, xcsv_file.badchars);
         } else {
-            description = xstrdup("");
+            /* no description -- let description default on output */
         }
     } else {
         description = csv_stringclean(wpt->description, xcsv_file.badchars);
@@ -886,7 +885,8 @@ xcsv_waypt_pr(const waypoint *wpt)
             sprintf(buff, fmp->printfc, fmp->val);
         } else
         if (strcmp(fmp->key, "SHORTNAME") == 0) {
-            sprintf(buff, fmp->printfc, shortname);
+            sprintf(buff, fmp->printfc, 
+                (shortname && *shortname) ? shortname : fmp->val);
         } else
         if (strcmp(fmp->key, "ANYNAME") == 0) {
             if (wpt->shortname) {
@@ -898,7 +898,7 @@ xcsv_waypt_pr(const waypoint *wpt)
             if (wpt->notes) {
                 anyname = xstrdup(wpt->notes);
             } else
-                anyname = xstrdup("");
+                anyname = xstrdup(fmp->val);
 
             if ((anyname) && (global_opts.synthesize_shortnames)) {
                 anyname = xstrdup(shortname);
@@ -909,10 +909,12 @@ xcsv_waypt_pr(const waypoint *wpt)
             xfree(anyname);
         } else
         if (strcmp(fmp->key, "DESCRIPTION") == 0) {
-            sprintf(buff, fmp->printfc, description);
+            sprintf(buff, fmp->printfc, 
+                (description && *description) ? description : fmp->val);
         } else
         if (strcmp(fmp->key, "NOTES") == 0) {
-           sprintf(buff, fmp->printfc, wpt->notes? wpt->notes : "");
+           sprintf(buff, fmp->printfc, 
+               (wpt->notes && *wpt->notes) ? wpt->notes : fmp->val);
         } else
         if (strcmp(fmp->key, "URL") == 0) {
            int off = 0;
@@ -923,13 +925,16 @@ xcsv_waypt_pr(const waypoint *wpt)
            if (wpt->url)
                sprintf(buff + off, fmp->printfc, wpt->url);
            else
-               strcpy(buff, "\"\"");
+               strcpy(buff, (fmp->val && *fmp->val) ? fmp->val : "\"\"");
         } else
         if (strcmp(fmp->key, "URL_LINK_TEXT") == 0) {
-            sprintf(buff, fmp->printfc, NONULL(wpt->url_link_text));
+            sprintf(buff, fmp->printfc, 
+                (wpt->url_link_text && *wpt->url_link_text) ? wpt->url_link_text : fmp->val);
         } else
         if (strcmp(fmp->key, "ICON_DESCR") == 0) {
-            sprintf(buff, fmp->printfc, NONULL(wpt->icon_descr));
+            sprintf(buff, fmp->printfc, 
+                (wpt->icon_descr && *wpt->icon_descr) ? 
+                wpt->icon_descr : fmp->val);
         } else
 
         /* LATITUDE CONVERSION***********************************************/
index b013e04ce6d8921782d5b340792e541ea55f3199..c5737f5b522366d0175b178494facb56d21999e7 100644 (file)
@@ -387,3 +387,11 @@ EXAMPLES:
 For examples on using the XCSV module, please see the *.style files in
 the style/ subdirectory of GPSBabel.  
 
+MISCELLANEOUS NOTES:
+--------------------
+ o DEFAULT VALUES
+   Default values are supported for any output fields that contain pure 
+   character data output such as URL and NOTES.  Default values are only
+   written on output and are not used to supplement missing input.  When 
+   using default values your mileage will vary greatly depending on the 
+   input formats used to populate waypoint data.